<template>
  <el-menu
    default-active="home"
    class="el-menu-vertical-demo"
    @open="handleOpen"
    @close="handleClose"
    :collapse="isCollapse"
    background-color="#1D2E56"
    text-color="#fff"
    active-text-color="#5AB1EF"
  >
    <h3>{{ isCollapse ? "后台" : "通用后台管理系统" }}</h3>
    <!--没有子菜单-->
    <el-menu-item
      v-for="item in getData.filter((item) => !item.children)"
      :key="item.name"
      :index="item.name"
      @click="clickMenu(item)"
    >
      <i :class="`el-icon-${item.icon}`"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>
    <!--有子菜单-->
    <el-submenu
      v-for="item in getData.filter((item) => item.children)"
      :key="item.label"
      :index="item.label"
    >
      <template slot="title">
        <i :class="`el-icon-${item.icon}`"></i>
        <span slot="title">{{ item.label }}</span>
      </template>
      <el-menu-item-group v-for="subItem in item.children" :key="subItem.path">
        <el-menu-item @click="clickMenu(subItem)" :index="subItem.path">{{
          subItem.label
        }}</el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>

<script>
import { mapState } from "vuex";

export default {
  props: {
    getData: [],
    type: Array,
    // eslint-disable-next-line vue/require-prop-type-constructor
    required: true,
  },
  // eslint-disable-next-line vue/multi-word-component-names
  name: "Aside",
  data() {
    return {
      //控制菜单展开
      menuDate: this.getData,
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    //点击跳转
    clickMenu(item) {
      //跳转判断，如何是跳当前页面就不跳转
      if (
        this.$route.path !== item.path &&
        !(this.$route.path === "/home" && item.path === "/main/home")
      ) {
        this.$router.push(item.path);
      }
    },
  },
  computed: {
    ...mapState(["isCollapse"]),
    //没有子菜单
  },
  mounted() {},
};
</script>

<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 260px;
  min-height: 400px;
}
.el-menu {
  height: 100%;
  overflow: auto;
  border: none;
  h3 {
    text-align: center;
    color: #fff;
    line-height: 48px;
    font-size: 16px;
    font-weight: 400;
  }
}
</style>
